<!doctype html>
<html>
    <head>
        <title>Errors</title>
    </head>
    <body>
        <?php
            //error handler function
            function customError($errno, $errstr)
              {
              echo "<b>Error:</b> [$errno] $errstr<br/>";
              }
            //set error handler
            set_error_handler("customError");
            //trigger error
            echo($test);
            
            $test=2;
            if ($test>1)
            {
            trigger_error("Value must be 1 or below");
            }

            //error handler function
            function customError2($errno, $errstr)
              {
              echo "<b>Error:</b> [$errno] $errstr<br>";
              echo "Ending Script";
              die();
              }
            //set error handler
            set_error_handler("customError2",E_USER_WARNING);
            //trigger error
            $test=2;
            if ($test>1)
              {
              trigger_error("Value must be 1 or below",E_USER_WARNING);
              }
              
           /*
            * To send an e-mail with the error you use error_log inside the error handling function:
            * error_log("Error: [$errno] $errstr",1,"someone@example.com","From: webmaster@example.com");
            */
        ?>
    </body>
</html>
